package com.electromagnetic.industry.software.manage.controller;

import cn.hutool.core.lang.Assert;
import com.electromagnetic.industry.software.common.annotations.UserOperation;
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
import com.electromagnetic.industry.software.manage.pojo.req.RecycleFileQueryDTO;
import com.electromagnetic.industry.software.manage.service.FileRecycleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/data/ed/recycle/file")
public class FileRecycleController {

    @Resource
    private FileRecycleService fileRecycleService;

    @RequestMapping("list")
    @UserOperation(value = "查看回收站", modelName = UserOperationModuleEnum.BACKUP_FILE)
    public ElectromagneticResult<?> list(@RequestBody RecycleFileQueryDTO pars) {
        return fileRecycleService.list(pars);
    }

    @RequestMapping("remove")
    @UserOperation(value = "彻底清除文件", modelName = UserOperationModuleEnum.BACKUP_FILE)
    public ElectromagneticResult<?> remove(@RequestParam String fileId) {
        Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue()), "当前用户没有删除文件权限");
        return fileRecycleService.remove(fileId);
    }

    @RequestMapping("recover")
    @UserOperation(value = "文件恢复", modelName = UserOperationModuleEnum.BACKUP_FILE)
    public ElectromagneticResult<?> recover(@RequestParam String fileId) {
        Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue()), "当前用户没有文件恢复权限");
        return fileRecycleService.recover(fileId);
    }

}
